slimecing

a fighting game featuring slimes and swords
Log | Files | Refs | README

TMP_SDF-Surface-Mobile.shader (3433B)


      1 // Simplified version of the SDF Surface shader :
      2 // - No support for Bevel, Bump or envmap
      3 // - Diffuse only lighting
      4 // - Fully supports only 1 directional light. Other lights can affect it, but it will be per-vertex/SH.
      5 
      6 Shader "TextMeshPro/Mobile/Distance Field (Surface)" {
      7 
      8 Properties {
      9 	_FaceTex			("Fill Texture", 2D) = "white" {}
     10 	_FaceColor			("Fill Color", Color) = (1,1,1,1)
     11 	_FaceDilate			("Face Dilate", Range(-1,1)) = 0
     12 
     13 	_OutlineColor		("Outline Color", Color) = (0,0,0,1)
     14 	_OutlineTex			("Outline Texture", 2D) = "white" {}
     15 	_OutlineWidth		("Outline Thickness", Range(0, 1)) = 0
     16 	_OutlineSoftness		("Outline Softness", Range(0,1)) = 0
     17 
     18 	_GlowColor			("Color", Color) = (0, 1, 0, 0.5)
     19 	_GlowOffset			("Offset", Range(-1,1)) = 0
     20 	_GlowInner			("Inner", Range(0,1)) = 0.05
     21 	_GlowOuter			("Outer", Range(0,1)) = 0.05
     22 	_GlowPower			("Falloff", Range(1, 0)) = 0.75
     23 
     24 	_WeightNormal		("Weight Normal", float) = 0
     25 	_WeightBold			("Weight Bold", float) = 0.5
     26 
     27 	// Should not be directly exposed to the user
     28 	_ShaderFlags		("Flags", float) = 0
     29 	_ScaleRatioA		("Scale RatioA", float) = 1
     30 	_ScaleRatioB		("Scale RatioB", float) = 1
     31 	_ScaleRatioC		("Scale RatioC", float) = 1
     32 
     33 	_MainTex			("Font Atlas", 2D) = "white" {}
     34 	_TextureWidth		("Texture Width", float) = 512
     35 	_TextureHeight		("Texture Height", float) = 512
     36 	_GradientScale		("Gradient Scale", float) = 5.0
     37 	_ScaleX				("Scale X", float) = 1.0
     38 	_ScaleY				("Scale Y", float) = 1.0
     39 	_PerspectiveFilter	("Perspective Correction", Range(0, 1)) = 0.875
     40 
     41 	_VertexOffsetX		("Vertex OffsetX", float) = 0
     42 	_VertexOffsetY		("Vertex OffsetY", float) = 0
     43 	
     44 	//_MaskCoord		("Mask Coords", vector) = (0,0,0,0)
     45 	//_MaskSoftness		("Mask Softness", float) = 0
     46 }
     47 
     48 SubShader {
     49 
     50 	Tags {
     51 		"Queue"="Transparent"
     52 		"IgnoreProjector"="True"
     53 		"RenderType"="Transparent"
     54 	}
     55 
     56 	LOD 300
     57 	Cull [_CullMode]
     58 
     59 	CGPROGRAM
     60 	#pragma surface PixShader Lambert alpha:blend vertex:VertShader noforwardadd nolightmap nodirlightmap
     61 	#pragma target 3.0
     62 	#pragma shader_feature __ GLOW_ON
     63 
     64 	#include "TMPro_Properties.cginc"
     65 	#include "TMPro.cginc"
     66 
     67 	half _FaceShininess;
     68 	half _OutlineShininess;
     69 
     70 	struct Input
     71 	{
     72 		fixed4	color		: COLOR;
     73 		float2	uv_MainTex;
     74 		float2	uv2_FaceTex;
     75 		float2  uv2_OutlineTex;
     76 		float2	param;					// Weight, Scale
     77 		float3	viewDirEnv;		
     78 	};
     79 
     80 	#include "TMPro_Surface.cginc"
     81 
     82 	ENDCG
     83 
     84 	// Pass to render object as a shadow caster
     85 	Pass
     86 	{
     87 		Name "Caster"
     88 		Tags { "LightMode" = "ShadowCaster" }
     89 		Offset 1, 1
     90 
     91 		Fog {Mode Off}
     92 		ZWrite On ZTest LEqual Cull Off
     93 
     94 		CGPROGRAM
     95 		#pragma vertex vert
     96 		#pragma fragment frag
     97 		#pragma multi_compile_shadowcaster
     98 		#include "UnityCG.cginc"
     99 
    100 		struct v2f {
    101 			V2F_SHADOW_CASTER;
    102 			float2	uv			: TEXCOORD1;
    103 			float2	uv2			: TEXCOORD3;
    104 			float	alphaClip	: TEXCOORD2;
    105 		};
    106 
    107 		uniform float4 _MainTex_ST;
    108 		uniform float4 _OutlineTex_ST;
    109 		float _OutlineWidth;
    110 		float _FaceDilate;
    111 		float _ScaleRatioA;
    112 
    113 		v2f vert( appdata_base v )
    114 		{
    115 			v2f o;
    116 			TRANSFER_SHADOW_CASTER(o)
    117 			o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
    118 			o.uv2 = TRANSFORM_TEX(v.texcoord, _OutlineTex);
    119 			o.alphaClip = o.alphaClip = (1.0 - _OutlineWidth * _ScaleRatioA - _FaceDilate * _ScaleRatioA) / 2;
    120 			return o;
    121 		}
    122 
    123 		uniform sampler2D _MainTex;
    124 
    125 		float4 frag(v2f i) : COLOR
    126 		{
    127 			fixed4 texcol = tex2D(_MainTex, i.uv).a;
    128 			clip(texcol.a - i.alphaClip);
    129 			SHADOW_CASTER_FRAGMENT(i)
    130 		}
    131 		ENDCG
    132 	}
    133 }
    134 
    135 CustomEditor "TMPro.EditorUtilities.TMP_SDFShaderGUI"
    136 }